package com.linkoog.devtools.intellij.ui.tree;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;

public class ListTreeWithToolbarPanel extends ListTreePanel implements Disposable{

    protected DefaultActionGroup toolbarActionGroup;

    public ListTreeWithToolbarPanel(@NotNull final JTree tree, TreeCellRenderer treeCellRenderer, DefaultActionGroupProvider actionGroupProvider , Disposable parentDisposable) {
        super(tree,treeCellRenderer, parentDisposable);

        toolbarActionGroup = actionGroupProvider.get(this);
        ActionManager actionManager = ActionManager.getInstance();
        ActionToolbar actionToolbar = actionManager.createActionToolbar(ActionPlaces.TOOLBAR, toolbarActionGroup, true);
        actionToolbar.setTargetComponent(tree);
        JComponent toolbarComponent = actionToolbar.getComponent();
        toolbarComponent.setBorder(JBUI.Borders.customLineBottom(new JBColor(Gray._214, new Color(30, 31, 34))));
        add(toolbarComponent, BorderLayout.NORTH);
    }

    public void refreshRestServiceTree(){
    }


    @Override
    public void dispose() {
    }

    @FunctionalInterface
    public interface DefaultActionGroupProvider{
        DefaultActionGroup get(ListTreeWithToolbarPanel listTreeWithToolbarPanel);
    }

}
